
import {size, formItemLayout, getImages, getFileList } from '../../utils/common';
import React from 'react';
import { Modal, Form, Input, Select } from 'antd';
import * as api from '../../api/api';
import { FormComponentProps } from 'antd/lib/form';
export interface StoreSettingEditProps extends FormComponentProps {
    visible: boolean,
    storeSetting?: api.SingleUserMallStoreSettingsVOStoreSettingVO,
    onSave: (any) => void,
    onCancel: () => void,
}
class StoreSettingEdit extends React.PureComponent<StoreSettingEditProps, any>{
    constructor(props) {
        super(props);
    }

    componentDidMount() {
        const id = this.props.storeSetting && this.props.storeSetting.id;
        this.setState({id:id});
    }

    ok = (e) => {
        e.preventDefault();
        this.props.form.validateFieldsAndScroll((err, form) => {
            if (!err) {
                form['id'] = this.state.id;
                this.props.onSave(form);
            }
        });
    }

    cancel = () => {
        this.props.onCancel();
    }
    

    render(): JSX.Element {
        const { getFieldDecorator } = this.props.form;
        const { storeSetting } = this.props;
        return (
            <Modal
                title='商城设置信息'
                visible={this.props.visible}
                onOk={this.ok}
                onCancel={this.cancel}
                maskClosable={true}
            >
                <Form>
                    <Form.Item label="描述" {...formItemLayout}>
                        {getFieldDecorator('description', {
                            rules: [
                                {
                                    required: true,
                                    message: '请输入描述'
                                }
                            ],
                            initialValue: storeSetting && storeSetting.description
                        })(<Input size={size} 
                            placeholder="请输入描述" />)}
                    </Form.Item>
                    <Form.Item label="设置值" {...formItemLayout}>
                        {getFieldDecorator('value', {
                            rules: [
                                {
                                    required: true,
                                    message: '请输入值'
                                }
                            ],
                            initialValue: storeSetting && storeSetting.value
                        })(<Input size={size} height="50px"
                            placeholder="请输入值" />)}
                    </Form.Item>
                </Form>
            </Modal>)
    }
}

export default Form.create()(StoreSettingEdit);